<?php
/**
 * tvb log file by date time appender
==================================
<appender>file</appender>
<file>
	<out_class>DateTimeFile</out_class>
	<pattern>SimpleText</pattern>
	<path>/data/logs</path>
</file>
==================================
 * @author William Hu <william.hu@achievo.com>
 * @version 1.0
 * @package TVBLog
 */
require_once 'TVB/Logger/Appender/Interface.php';
class TVB_Logger_Appender_DateTimeFile implements TVB_Logger_Appender_Interface
{
    public function write($log_entity)
    {
		$data_info = TVB_Logger_Config::get('file', $log_entity->category);
		$path = $data_info['path'];
		$file = $path.date("Ymd").'.log';
		if(!file_exists($path)){
			@mkdir($path, 0777, true);
		}
		if (!file_exists($file)){
			error_log('', 3, $file);
			@chmod($file, 0777);
		}
		require_once 'TVB/Logger/Pattern.php';
		$pattern = TVB_Logger_Pattern::get($data_info['pattern']);
		$format_text = $pattern->toString($log_entity);
		return error_log($format_text, 3, $file);

    }
}
?>